const fs = require("fs");
const path = require("path");

function rename(dir) {
   
    var list = fs.readdirSync(dir)
    list.forEach(function(file, index) {
       
        file = dir + '/' + file
        
      
        var stat = fs.statSync(file)
      
        if (stat && stat.isDirectory()){
           
            rename(file)
        }else{
            
            var extname = path.extname(file);
            fs.rename(file, 'C:\\Users\\QI\\Desktop\\WeiXin\\' +  index + '.png', (err) => {
                
                if (err) throw err; // 如果发生错误则抛出异常
               
            });
        }
       
    })
   
}

rename('C:\\Users\\QI\\Desktop\\WeiXin')